package com.atguigu.tingshu.account.mq;

import com.atguigu.tingshu.account.service.UserAccountService;
import com.atguigu.tingshu.common.constant.KafkaConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component  //加入spring容器
@Slf4j
public class AccountReceiver {
    @Autowired
    private UserAccountService userAccountService;
    @KafkaListener(topics = KafkaConstant.QUEUE_USER_REGISTER)
    public void initAccount(ConsumerRecord<String,String> record){
        String value = record.value();
        if (!StringUtils.isEmpty(value)){
            userAccountService.initAccount(Long.parseLong(value));
            log.info("用户账号初始化成功了……userId:{}",value);
        }
    }
}
